﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PhuongDoAn.Admin.Country.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Danh sách các tài khoản admin</title>
    <script type="text/javascript" language="javascript">
        var prepare = function (grid, toolbar, rowIndex, record) {
            //  toolbar.items.get(0).setTooltip('Xem chi tiết');
            toolbar.items.get(0).setTooltip('Sửa');
            toolbar.items.get(1).setTooltip('Xác nhận xóa');
        };
        var doubleClick = function (dataview, record, item, index, e) {
            commandHandler("edit", record);
        }
        var reLoadData = function () {
            applyFilter();
        }

        var reportResult = function (strMessage) {
            Ext.net.Notification.show({
                iconCls: 'icon-information',
                hideDelay: 2000,
                pinEvent: 'click',
                html: strMessage,
                title: 'Thông báo'
            });
            applyFilter();
        }

        var applyFilter = function () {
            App.gpDocument.store.loadPage(1);
            App.gpDocument.store.reload();

        }
        var clearFilter = function () {
            //set lai gia tri trang
            App.txtKeyWord.setValue('');
            App.gpDocument.store.reload();
        }
        

        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "add":
                    var url = 'Country/Edit.aspx';
                    var title = 'Thêm mới danh mục quốc gia';
                    id = "Doc_Book_Edit";
                    window.top.newWindow(url, { id: id, title: title, height: 450, width: 1000, modal: true });
                    break;
                case "edit":
                    url = 'Country/Edit.aspx?ItemID=' + record.data.CountryID;
                    title = 'Sửa danh mục quốc gia';
                    id = "Doc_Book_Edit";
                    window.top.newWindow(url, { id: id, title: title, height: 450, width: 1000, modal: true });
                    break;
              
                case "delete":
                    Ext.Msg.confirm('Xác nhận', '<span style="color:red;">Xác nhận xóa :</span><b> ' + record.data.CountryName + '</b>', function (btn) {
                        if (btn == "yes") {
                            App.direct.Delete(record.data.CountryID, {
                                success: function (result) {
                                    applyFilter();
                                },
                                eventMask: {
                                    showMask: true,
                                    minDelay: 500
                                }
                            });
                        }
                    });
                    break;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="Resourcemanager1" runat="server" ShowWarningOnAjaxFailure="false">
    </ext:ResourceManager>
    <%--Store dung du lieu--%>
    <ext:Store ID="storeData" runat="server" RemoteSort="true" PageSize="20" AutoLoad="true">
        <Proxy>
            <ext:AjaxProxy Url="Handler/ListHandler.ashx">
                <ActionMethods Read="GET">
                </ActionMethods>
                <Reader>
                    <ext:JsonReader Root="Data" TotalProperty="TotalRecords">
                    </ext:JsonReader>
                </Reader>
            </ext:AjaxProxy>
        </Proxy>
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="={0}" />
        </AutoLoadParams>
        <Model>
            <ext:Model ID="Model4" runat="server">
                <Fields>
                    <ext:ModelField Name="CountryID" />
                    <ext:ModelField Name="CountryName" />
                </Fields>
            </ext:Model>
        </Model>
        <Sorters>
            <ext:DataSorter Property="CountryName" Direction="ASC">
            </ext:DataSorter>
        </Sorters>
        <Parameters>
            <ext:StoreParameter Name="limit" Mode="Raw" Value="#{cbPageSize}.getValue()" />
            <ext:StoreParameter Name="query" Mode="Raw" Value="#{txtKeyWord}.getValue()" />
        </Parameters>
    </ext:Store>
    <ext:Viewport ID="vp" runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel runat="server" ID="Panel3" Title="Menu chức năng" Region="Center" Collapsible="false"
                Margins="0 0 0 5" Header="false" Border="false" Layout="BorderLayout">
                <Items>
                    <ext:Panel ID="Panel4" runat="server" Region="Center" Header="false" Border="false"
                        Layout="FitLayout">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:Button ID="btnAdd" runat="server" Text="Thêm mới" Icon="Add">
                                        <Listeners>
                                            <Click Handler="commandHandler('add');" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarFill />
                                    <ext:TextField ID="txtKeyWord" runat="server" MaxLength="255">
                                    </ext:TextField>
                                    <ext:Button ID="btnSearch" runat="server" Icon="Zoom">
                                        <Listeners>
                                            <Click Handler="applyFilter();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnClear" runat="server" Icon="ArrowRefresh">
                                        <Listeners>
                                            <Click Handler="clearFilter();" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:GridPanel ID="gpDocument" runat="server" Frame="true" AutoExpandColumn="Title"
                                StripeRows="true" Split="true" AutoEncode="true" StoreID="storeData" Layout="FitLayout"
                                Region="Center" Border="false">
                                <ColumnModel ID="ColumnModel1" runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn ID="RowNumbererColumn1" runat="server" Text="STT" Width="30"
                                            Align="Center" Resizable="false" />
                                        <ext:CommandColumn ID="CommandColumn1" runat="server" Align="Center" Resizable="false"
                                            ColumnID="ColumnIDTool" Wrap="true" Width="80">
                                            <Commands>
                                                <ext:GridCommand Icon="TableEdit" CommandName="edit" />
                                                <ext:GridCommand Icon="Delete" CommandName="delete" />
                                            </Commands>
                                            <PrepareToolbar Fn="prepare" />
                                            <Listeners>
                                                <Command Handler="commandHandler(command,  record);" />
                                            </Listeners>
                                        </ext:CommandColumn>
                                       
                                        <ext:Column ID="Column2" DataIndex="CountryName" TdCls="wrap" Text="Tên quốc gia" ColumnID="Title"
                                            runat="server" Groupable="false" Flex="1">
                                            <Renderer Format="HtmlEncode">
                                            </Renderer>
                                        </ext:Column>
                                       
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
                                    </ext:RowSelectionModel>
                                </SelectionModel>
                                <BottomBar>
                                    <ext:PagingToolbar AutoScroll="true" ID="PagingToolbar1" runat="server" PageSize="20"
                                        EmptyMsg="Hiện chưa có bản ghi nào">
                                        <Items>
                                            <ext:Label ID="lblPageSize" runat="server" Text="Số bản ghi trên trang" />
                                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                                            <ext:ComboBox ID="cbPageSize" runat="server" Width="55" Editable="false">
                                                <Items>
                                                    <ext:ListItem Text="10" />
                                                    <ext:ListItem Text="20" />
                                                    <ext:ListItem Text="30" />
                                                </Items>
                                                <SelectedItems>
                                                    <ext:ListItem Value="20" Text="20" />
                                                </SelectedItems>
                                                <Listeners>
                                                    <Select Handler="#{gpDocument}.store.pageSize= parseInt(this.getValue()); #{gpDocument}.store.reload();" />
                                                </Listeners>
                                            </ext:ComboBox>
                                        </Items>
                                    </ext:PagingToolbar>
                                </BottomBar>
                                <Listeners>
                                    <ItemDblClick Fn="doubleClick" />
                                </Listeners>
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>

